//
//  TalkAboutTableViewCell.m
//  STL_ Animation
//
//  Created by 孙健 on 16/4/5.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "TalkAboutTableViewCell.h"
#import <AVFoundation/AVFoundation.h>
@implementation TalkAboutTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageViewHead = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.labelName = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelMost = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelTime = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelMost.numberOfLines = 0;
        self.labelMost.font = [UIFont systemFontOfSize:14];
        self.labelName.font = [UIFont systemFontOfSize:14];
        self.labelTime.font = [UIFont systemFontOfSize:12];
        
        self.labelName.textColor = [UIColor whiteColor];
        self.labelTime.textColor = [UIColor whiteColor];
        self.labelMost.textColor = [UIColor whiteColor];
        
        [self.contentView addSubview:self.imageViewHead];
        [self.contentView addSubview:self.labelTime];
        [self.contentView addSubview:self.labelName];
        [self.contentView addSubview:self.labelMost];
    }
    
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.imageViewHead.frame = CGRectMake(20, 10, 50, 50);
    [self.imageViewHead.layer setCornerRadius:CGRectGetHeight([self.imageViewHead bounds])/2];
    self.imageViewHead.layer.masksToBounds = YES;
    self.labelName.frame = CGRectMake(80, 10, self.contentView.bounds.size.width - 80, 50);
    self.labelMost.frame = CGRectMake(10, 70, self.contentView.bounds.size.width - 20, self.contentView.bounds.size.height/3);
    self.labelTime.frame = CGRectMake(10,  self.labelMost.bounds.size.height + 70, self.contentView.bounds.size.width - 20, 30);
}

- (CGFloat)cellHeight{
    //    字体大小
    NSDictionary *fontDic = [NSDictionary dictionaryWithObject:self.labelName.font forKey:NSFontAttributeName];
    // 计算宽高
    CGSize size = [self.labelName.text boundingRectWithSize:CGSizeMake(10000, 40) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:fontDic context:nil].size;
    // 返回计算完成的高度
    return size.height;
}



- (void)setTalkAboutModel:(ChannelPageTalkAboutModel *)talkAboutModel {
    
    _talkAboutModel = talkAboutModel;
    [self.imageViewHead sd_setImageWithURL:[NSURL URLWithString:talkAboutModel.userHeadImg]];
    self.labelName.text = talkAboutModel.userName;
    self.labelMost.text = talkAboutModel.content;
    self.labelTime.text = talkAboutModel.dateCreated;
}

@end
